package LeetCode;

public class LC_485_MaxConsecutiveOnes {

    public static void main(String[] args) {

    }

    public class Solution {
        public int findMaxConsecutiveOnes(int[] nums) {
            int dp[] = new int[nums.length + 1];
            int max = 0;
            for (int i = nums.length - 1; i >= 0; i--)
                if (nums[i] == 1) {
                    dp[i] = dp[i + 1] + 1;
                    max = Math.max(dp[i], max);
                }
            return max;
        }
    }

    static class Solution_2 {
        public int findMaxConsecutiveOnes(int[] nums) {
            int result = 0;
            int temp = 0;
            for (int num : nums) {
                if (num == 0)
                    temp = 0;
                else {
                    temp += 1;
                    result = Math.max(temp, result);
                }
            }
            return result;
        }
    }

    static class Solution_3 {
        public int findMaxConsecutiveOnes(int[] nums) {
            int dp[] = new int[nums.length];
            int max = 0;
            for (int i = 0; i < nums.length; i++)
                if (nums[i] == 1) {
                    if (i == 0)
                        dp[i] = 1;
                    else
                        dp[i] = dp[i - 1] + 1;
                    max = Math.max(dp[i], max);
                }
            return max;
        }
    }
}